#include<iostream>
#include<string>
using namespace std;
const int N = 1e6 + 10;
int f1[N], f2[N];
int n;
string s;
int main()
{
	cin >> n;
	cin >> s;
	s = " " + s;
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		/*f1[i] = f1[i - 1];
		if (s[i] == '1') {
			f1[i] = max(f1[i] + 1, sum);
			sum++;
		}
		else {
			sum = 0;
		}*/
		if (s[i] == '1') {
			sum++;
		}
		else sum = 0;
		f1[i] = sum;
	}
	sum = 0;
	for (int i = n; i >= 1; i--) {
		f2[i] = f2[i + 1];
		if (s[i] == '1') {
			f2[i] = max(f2[i], sum);
			sum++;
		}
		else {
			f2[i] = max(f2[i], sum);
			sum = 0;
		}
	}
	int ans = 0;
	int res = 0;
	for (int i = 1; i <= n; i++) {
		//cout << "f1[i]==" << f1[i] << endl;
		//cout << "f2[i]==" << f2[i] << endl;
		if (s[i] == '1') {
			/*if (ans < f1[i] + f2[i] + 1) {
				ans = f1[i] + f2[i] + 1;
				res = i;
			}*/
			ans = max(ans, f1[i] + f2[i]);
		}
	}
	cout << ans << endl;
	//cout << res << endl;
	return 0;
}